package com.wolf.etl.core.filter;

import com.wolf.util.StringUtils;
import com.wolf.vo.BaseResult;
import org.springframework.stereotype.Component;

/**
 * @author sdyang
 * @date 2019/10/14 8:34
 **/
@Component("iN")
public class IN extends AbstractFilter{
    @Override
    public BaseResult filter(String columnName, String... value) {

        StringBuffer sql = new StringBuffer();
        int index =0;
        for(String s:value){
            if(StringUtils.isNumeric(s)){
                sql.append(s);
            }else{
                sql.append("'").append(s).append("'");
            }
            index++;
            if(index<value.length){
                sql.append(",");
            }
        }
        String filterStr = String.format(" and %s in (%s)", columnName, sql);

        BaseResult result = BaseResult.getSuccess(filterStr);
        return result;
    }
}
